package com.eazyshop.goods.handler;

import com.eazyshop.common.pojo.Result;
import com.eazyshop.common.pojo.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 * 异常统一处理类
 */
@ControllerAdvice
public class BaseExceptionHandler {
    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public Result  error(Exception e, HttpServletRequest request, HttpServletResponse response){
        // 打印堆栈信息
        System.out.println("==================");

        System.out.println(request.getRequestURI());

        System.out.println(response.getStatus());

        System.out.println("==================");
        e.printStackTrace();
        // 返回结果
        return new Result(false, StatusCode.ERROR,e.getMessage());
    }

}
